//
//  LLActionCell.swift
//  LiLi
//
//  Created by liuzhu on 2019/1/21.
//  Copyright © 2019 liuzhu. All rights reserved.
//

import UIKit

class LLActionCell: UITableViewCell {

    public var action:LLAction?{
        didSet{
            nameLabel.text = action?.titleName
            desLabel.text = action?.des
            switch action!.repeatTag {
            case ActionRepeatTag.REPEAT_NONE:
                repeatTagLabel.text = "一次"
                dateLabel.text = "\(action?.dateStr ?? "") \(action?.timeStr ?? "")"
                break
            case ActionRepeatTag.REPEAT_DAY:
                repeatTagLabel.text = "每日"
                dateLabel.text = "\(action?.timeStr ?? "")"
                break
            case ActionRepeatTag.REPEAT_WEEK:
                repeatTagLabel.text = "每周"
                let date = LLDateUtil.shareLLDateUtil().stringConvertDate(string: action!.dateStr!, dateFormat: "yyyy-MM-dd")
                let week = LLDateUtil.shareLLDateUtil().getWeekDay(date: date)
                switch week {
                case 1:
                    dateLabel.text = "周日 \(action?.timeStr ?? "")"
                    break
                case 2:
                    dateLabel.text = "周一 \(action?.timeStr ?? "")"
                    break
                case 3:
                    dateLabel.text = "周二 \(action?.timeStr ?? "")"
                    break
                case 4:
                    dateLabel.text = "周三 \(action?.timeStr ?? "")"
                    break
                case 5:
                    dateLabel.text = "周四 \(action?.timeStr ?? "")"
                    break
                case 6:
                    dateLabel.text = "周五 \(action?.timeStr ?? "")"
                    break
                case 7:
                    dateLabel.text = "周六 \(action?.timeStr ?? "")"
                    break
                default:
                    break
                }
                break
            case ActionRepeatTag.REPEAT_MONTH_SUN:
                repeatTagLabel.text = "每月"
                let arr = action!.dateStr?.components(separatedBy: "-")
                dateLabel.text = "\(arr?.last ?? "")日 \(action?.timeStr ?? "")"
                break
            case ActionRepeatTag.REPEAT_MONTH_MOON:
                repeatTagLabel.text = "每月"
                let date = LLDateUtil.shareLLDateUtil().stringConvertDate(string: action!.dateStr!, dateFormat: "yyyy-MM-dd")
                let chineseDateStr = LLDateUtil.shareLLDateUtil().gregorianToChineseDay(gregorianDate: date)
                dateLabel.text = "\(chineseDateStr) \(action?.timeStr ?? "")"
                break
            case ActionRepeatTag.REPEAT_YEAR_SUN:
                repeatTagLabel.text = "每年"
                let arr = action!.dateStr?.components(separatedBy: "-")
                dateLabel.text = "\(arr?[1] ?? "")月\(arr?.last ?? "")日 \(action?.timeStr ?? "")"
                break
            case ActionRepeatTag.REPEAT_YEAR_MOON:
                repeatTagLabel.text = "每年"
                let date = LLDateUtil.shareLLDateUtil().stringConvertDate(string: action!.dateStr!, dateFormat: "yyyy-MM-dd")
                let chineseDateStr = LLDateUtil.shareLLDateUtil().gregorianToChineseDate(gregorianDate: date)
                dateLabel.text = "\(chineseDateStr) \(action?.timeStr ?? "")"
                break
            }
        }
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = LLConst.backgroundGray()
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI(){
        contentView.addSubview(nameLabel)
        contentView.addSubview(desLabel)
        contentView.addSubview(repeatTagLabel)
        contentView.addSubview(dateLabel)
        contentView.addSubview(line)
    }
    
    private lazy var  nameLabel:UILabel = {
        let label = UILabel.init(frame: CGRect(x: 10, y: 5, width: UIScreen.main.bounds.size.width - 60, height: 20))
        label.textColor = UIColor.darkGray
        label.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold)
        label.textAlignment = NSTextAlignment.left
        return label
    }()
    
    private lazy var desLabel:UILabel = {
        let label = UILabel.init(frame: CGRect(x: 10, y: 30, width: UIScreen.main.bounds.size.width - 150, height: 40))
        label.textColor = UIColor.lightGray
        label.font = UIFont.systemFont(ofSize: 13)
        label.numberOfLines = 0
        label.textAlignment = NSTextAlignment.left
        return label
    }()
    
    private lazy var repeatTagLabel:UILabel = {
        let label = UILabel.init(frame: CGRect(x: nameLabel.frame.origin.x + nameLabel.bounds.size.width, y: 5, width: 40, height: 20))
        label.textColor =  UIColor.darkGray
        label.font = UIFont.systemFont(ofSize: 13)
        label.textAlignment = NSTextAlignment.right
        return label
    }()
    
    private lazy var dateLabel:UILabel = {
        let label = UILabel.init(frame: CGRect(x: desLabel.frame.origin.x + desLabel.bounds.size.width, y: 40, width: 130, height: 20))
        label.textColor = UIColor.lightGray
        label.font = UIFont.systemFont(ofSize: 12)
        label.textAlignment = NSTextAlignment.right
        return label
    }()
    
    private lazy var line:UIView = {
        let v = UIView.init(frame: CGRect(x: 0, y: 70, width: UIScreen.main.bounds.size.width, height: 3))
        v.backgroundColor = UIColor.white
        return v
    }()
}
